package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/users")
public class RestfulController {

    @GetMapping()
    public List<User> get(){
        ArrayList<User> list = new ArrayList<>();
        User user = new User(1L, "ming", "15");
        User user1 = new User(2L, "wang", "18");
        list.add(user);
        list.add(user1);
        return list;
    }
    @GetMapping("{id}")
    public User detail(@PathVariable Long id){
        User user = new User(id, "ming", "155");
        return user;
    }



    @PostMapping()
    public User post(){
        User user = new User(1L,"dafei","25");
        return user;
    }

    @PutMapping()
    public User put(User user){
        user.setName(user.getName() + "b");
        user.setAge(user.getAge() + "10");
        return user;
    }

    @DeleteMapping()
    public String delete(){
        return "成功";
    }
}
